package com.zs.blog.controller;

import com.zs.blog.model.ResponseResult;
import com.zs.blog.model.vo.PageInfoVO;
import com.zs.blog.model.vo.RoleListVO;
import com.zs.blog.model.vo.UserListVO;
import com.zs.blog.service.IRoleService;
import com.zs.blog.service.IUserRoleService;
import com.zs.blog.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Title: UserRoleController
 * @Author zs
 * @Package com.zs.blog.controller
 * @Date 2025/7/14 19:29
 * @description: 用户角色接口层
 */
@RestController
@Tag(name = "用户角色相关接口")
public class UserRoleController {

    public IUserRoleService userRoleService;

    public IUserService userService;

    public IRoleService roleService;

    public UserRoleController(IUserService userService, IRoleService roleService, IUserRoleService userRoleService) {
        this.userService = userService;
        this.roleService = roleService;
        this.userRoleService = userRoleService;
    }

    @GetMapping("/admin/role/userlist")
    @Operation(summary = "根据角色ID获取用户列表")
    public ResponseResult<PageInfoVO<UserListVO>> listUserByRoleId(@RequestParam Integer roleId,
                                                                   @RequestParam Integer pageNum,
                                                                   @RequestParam Integer pageSize) {
        PageInfoVO<UserListVO> listUser = userRoleService.listUserByRoleId(roleId, pageNum, pageSize);
        return ResponseResult.success(listUser);
    }


    @GetMapping("/admin/user/role/list")
    @Operation(summary = "根据用户ID获取未分配角色列表")
    public ResponseResult<PageInfoVO<RoleListVO>> listRoleByUserId(@RequestParam Long userId,
                                                                   @RequestParam Integer pageNum,
                                                                   @RequestParam Integer pageSize,
                                                                   @RequestParam List<Long> roleIdList) {
        PageInfoVO<RoleListVO> listRole = userRoleService.listRoleByUserId(userId,pageNum,pageSize,roleIdList);
        return ResponseResult.success(listRole);
    }
}
